package com.yueyang.sojourn.server.service.wx;

import com.yueyang.sojourn.server.common.CryptUtils;
import com.yueyang.sojourn.server.service.wx.model.WxSessionKey;
import org.apache.tomcat.util.codec.binary.Base64;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.nio.charset.Charset;

/**
 * ares-remoting  WxDataVerifyService
 *
 * @author Guangshan
 * @date 2017/11/5 15:37
 * @since 0.0.1
 */
@Service
public class WxDataVerifyManager {

    public String decryptData(String sessionKey, String encryptedData, String iv) {
        byte[] resultByte = CryptUtils.decryptAES(Base64.decodeBase64(encryptedData), Base64.decodeBase64(sessionKey), Base64.decodeBase64(iv));
        if(null != resultByte && resultByte.length > 0){
            return new String(resultByte, Charset.forName("UTF-8"));
        }
        return null;
    }

}
